package Controller;


import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.swing.JOptionPane;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Promociones
 */
public class SendMail {
               
        public static boolean SendMail(final String Username,final String PassWord,String Body,String To,String Subject){
            Properties props = new Properties();
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.host", "mail.genuinexpress.com");
            props.put("mail.smtp.port", "587");

            try {
                Session session = Session.getInstance(props,
                    new javax.mail.Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(Username, PassWord);
                        }
                    });
                Message message = new MimeMessage(session);                   
                message.setFrom(new InternetAddress(Username));
                message.setRecipients(Message.RecipientType.TO,InternetAddress.parse(To));
                message.setSubject(Subject);
                message.setContent(Body,"text/html");
                Transport.send(message);
                return true;
            } catch (MessagingException e) {
                return false;
            }
    }
}

